package top.ezzz.search.model;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

/**
 * @author noear
 * @since 1.0.3
 */
public class EsSort {

    private final JSONArray oNode;

    public EsSort(JSONArray oNode) {
        this.oNode = oNode;
    }

    public EsSort addByAes(String field) {
        JSONObject obj = JSONUtil.createObj();
        if (obj.get(field) == null) {
            obj.set(field, JSONUtil.createObj());
        }
        obj.getJSONObject(field).set("order", "asc");
        oNode.add(obj);
        return this;
    }

    public EsSort addByDesc(String field) {
        JSONObject obj = JSONUtil.createObj();
        if (obj.get(field) == null) {
            obj.set(field, JSONUtil.createObj());
        }
        obj.getJSONObject(field).set("order", "desc");
        oNode.add(obj);
        return this;
    }
}
